<?php
namespace api\modules\v1\controllers;

use Yii;
use common\modules\mapp\models\MappVersionUpgrade;
use common\core\ApiException;
use common\core\base\BaseApiController;

class MappVersionUpgradeController extends BaseApiController
{

    public function actionCheck()
    {
        $app_id = Yii::$app->request->post('app_id');
        $version_major = Yii::$app->request->post('version_major');
        $version_mini = Yii::$app->request->post('version_mini');
        
        $version = MappVersionUpgrade::find()->where([
            'app_id' => $app_id
        ])
            ->orderBy('created_at desc')
            ->limit(1)->one();
        if ($version) 
        {
            if ($version->version_major == $version_major && $version->version_mini == $version_mini) {
                throw new ApiException('没有更新版本', 102);
            } else {
                return $version;
            }
        }
        else 
        {
            throw new ApiException('没有记录', 101);
        }
    }
}